package hot100;

public class maxProfit {
    public int maxProfit(int[] prices) {
        int minPric = Integer.MAX_VALUE;
        int max = 0;
        int n = prices.length;
        for(int i = 0;i < n;i++) {
            int price = prices[i];
            if(price < minPric) {
                minPric = price;
            }else if(price - minPric > max) {
                max = price - minPric;
            }
        }
        return max;
    }
}
